<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
	<title>我的</title>
	<link rel="stylesheet" type="text/css" href="../../lib/css/skin.css"/>
</head>
<body>
<div id="root">
	<div class="app_warp">
		<div class="app_head">
			<!--<span class="left back"></span>-->
			<span class="name">院校</span>
			<span class="right search"></span>
		</div>
		<div class="app_col_content clearfix">
			<div id="left_menu" class="left_menu"></div>
			<div class="right_content">
				<div class="spancol clearfix">
					<span tapmode onclick="showSubmenu(1)">专业</span>
					<span tapmode onclick="showSubmenu(0)">分数</span>
					<div id="submenu" class="submenu"></div>
				</div>
				<ul id="yuanxiaolist" class="yuanxiaolist"></ul>
			</div>
		</div>
	</div>
</div>

<script id="yuanxiao_menu_template" type="text/html">
	<ul>
		<% for(var topItem in left){ %>
			<li tapmode onclick="getArea(this,'top_<%:=topItem%>')">
				<%:=left[topItem]%>
			</li>
		<%}%>
		<% for(var area in areaData){ %>
			<li tapmode onclick="getArea(this,'area_<%:=areaData[area].id%>')" <%if(areaData[area].id===0){%>class="active"<%}%>>
				<%:=areaData[area].name%>
			</li>
		<%}%>
	</ul>
</script>

<script id="yuanxiao_submenu_template" type="text/html">

	<a class="type_0" tapmode onclick="getClassify([<%:=fraction['300以下'][0]%>,<%:=fraction['300以下'][1]%>])">
		300以下
	</a>
	<a class="type_0" tapmode onclick="getClassify([<%:=fraction['300-400分'][0]%>,<%:=fraction['300-400分'][1]%>])">
		300-400分
	</a>
	<a class="type_0" tapmode onclick="getClassify([<%:=fraction['400-500分'][0]%>,<%:=fraction['400-500分'][1]%>])">
		400-500分
	</a>
	<a class="type_0" tapmode onclick="getClassify([<%:=fraction['500以上'][0]%>,<%:=fraction['500以上'][1]%>])">
		500以上
	</a>

	<% for(var cla in classify){ %>
		<a class="type_1" tapmode onclick="getClassify(<%:=classify[cla].id%>)">
			<%:=classify[cla].name%>
		</a>
	<%}%>
</script>

<script id="yuanxiao_list_template" type="text/html">
	<%for(var i in data.school){%>
		<li data_min="<%:=data.school[i].min%>"
		    data_max="<%:=data.school[i].max%>"
		    class="<%if(i>30){%><%:='hide'%><%}%> xuexiaolist area_<%:=data.school[i].area_id%> <%:getTop=data.school[i].leftMenu%> <%:getDirection=data.school[i].direction%>"
		    tapmode onclick="api.openWin({name:'yuanxiao_view',url:'./yuanxiao_view.html',pageParam:{id:<%:=data.school[i].id%>}})">
				<img class="imgcache" src="<%:=img%>" data_src="<%:=data.src%><%:=data.school[i].logo%>" alt="">
				<%:subStr=data.school[i].name%>
		</li>
	<%}%>
	<li class="showmore" tapmode onclick="showmore()">
		显示更多
	</li>
</script>

<script>

	var
		area = 'area_0',
		selClass = null,
		selCF=null,
		list = null,
		thisList = null,
		page=0,
		showmore=function(){
			for(var i =30;i>0;i--){
				$('.xuexiaolist.hide').eq(page).addClass('show').removeClass('hide');
					page++;
				if(page>list.length){
					$('.showmore').hide();
				}
			}
		},
		formatSchoolData = function () {
			_$.loading.start();
			_$.ajax({
				interface: 'getSchoolIntro',
				call: function (data) {
					_$.template('yuanxiao_list_template', {
						data: data.data,
						img: _$.imgCache.default
					}, function (html) {
						$('#yuanxiaolist').html(html);
						_$.imgCache.load();
						list=$('.xuexiaolist');
						thisList=null;
					})
					_$.loading.end();
				}
			})
		},
		showSubmenu = function (index) {

			$('#submenu a').hide();
			$('#submenu a.type_' + index).show();
			if(selCF === index){
				$('#submenu').toggle();
			}else{
				$('#submenu').show();
				selCF = index;
			}
		},
		getArea = function (obj, data) {
			list=$('.xuexiaolist');
			$('#left_menu li').removeClass('active');
			$(obj).addClass('active');
			list.addClass('hide').removeClass('show');
			if(data==='area_0'){
				page = 0;
				list.map(function (i, item) {
					if (i < 30) {
						list.eq(i).addClass('show').removeClass('hide');
						page++;
					}
				})
				$('.showmore').show();
				area = data;
			}else{
				area = data;
				$('.showmore').hide();
				$('.'+data).removeClass('hide').addClass('show');
			}
			thisList = $('.xuexiaolist.show');
		},
		getClassify = function (data) {

			if (area === 'area_0') {
				thisList = list;
				$('.showmore').hide();
			} else if(thisList===null){
				thisList = $('.xuexiaolist.show');
			}

			thisList.addClass('hide').removeClass('show');

			if(_$.getType(data)==='number'){
				if(data===0){
					thisList.addClass('show').removeClass('hide');
				}else{
					thisList.map(function(i,item){
						if(thisList.eq(i).hasClass('direction_'+data)){
							thisList.eq(i).addClass('show').removeClass('hide');
						}else{
							thisList.eq(i).removeClass('show').addClass('hide');
						}
					})
				}
			}else{

				thisList.map(function(i,item){

					var item = $(item),
						max = item.attr('data_max'),
						min = item.attr('data_min');

					if (data[0] <= min && max <= data[1]) {
						item.removeClass('hide').addClass('show');
					}

				})
			}
			$('#submenu').hide();
		},
		appready = function () {
			_$.db.gets({
				'key': ['schoolMenu', 'area', 'classify'],
				'call': function (datas) {
					//初始化下拉菜单部分内容
					_$.template('yuanxiao_submenu_template', {
						'fraction': datas[0].fraction,
						'classify': datas[2]
					}, function (html) {
						$('#submenu').html(html);
					})
					//准备左侧内容数据
					var data = [],
						areaData = datas[1];
					for (var i in areaData.directly) {
						data.push(areaData.directly[i]);
					}
					for (var j in areaData.province) {
						data.push(areaData.province[j]);
					}
					datas[0].areaData = data;
					//初始化左侧内容html
					_$.template('yuanxiao_menu_template', datas[0], function (html) {
						$('#left_menu').html(html);
					})
					//请求新的学校数据
					formatSchoolData();
				}
			})
		};

</script>
<script src="../../lib/js/config.js"></script>
<script src="../../lib/js/jquery.js"></script>
<script src="../../lib/js/common.js"></script>
</body>
</html>